﻿using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SMS.UploadAPI.App_Start.Attributes
{
    /// <summary>
    /// 权限过滤特性,在需要进行权限过滤的action上添加该特性即可
    /// </summary>
    [AttributeUsage(AttributeTargets.Method)]
    public class PermissionAuthAttribute : Attribute, IAsyncActionFilter
    {
        public string PermissionCode { get; set; }
        public PermissionAuthAttribute(string permissionCode)
        {
            PermissionCode = permissionCode;
        }

        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            //var userQueryService = context.HttpContext.RequestServices.GetRequiredService<IUserQueryService>();
            ////获取该用户的菜单权限
            //var codeList = (await userQueryService.GetUserMenuPermission()).Data;
            //if (!codeList.Contains(PermissionCode))
            //{
            //    context.Result = new ContentResult { StatusCode = 403, Content = "您没有权限访问" };
            //}
            //else
            //{
            //    await next();
            //}
            await next();
        }
    }
}
